package com.iot08.api.service;

import com.iot08.common.entity.app.AnimalHeatSetting;
import com.iot08.common.entity.app.BloodOxygenSetting;
import com.iot08.common.service.base.BaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @version 1.0
 * @Description: 体温配置业务逻辑处理
 * @author: Rock
 * @time: 2021/5/7 9:50
 */
@Slf4j
@Service
public class AnimalHeatSettingService extends BaseService<AnimalHeatSetting> {

    /**
     * 获取记录，没有记录则添加默认记录
     *
     * @param id
     * @param openid
     * @time: 2021/3/8 19:09
     * @author: Rock
     * @version 1.0
     */
    public AnimalHeatSetting getById(String id, String openid) {
        AnimalHeatSetting setting = this.findById(id);
        if (setting == null) {
            setting = new AnimalHeatSetting();
            setting.setId(id);
            setting.setSetChangeTime(System.currentTimeMillis() / 1000);
            setting.setOpenid(openid);
            setting.setLastTemperature("0");
            setting.setLastDataTime(0l);
            setting.setSwitchStatus(0);
            setting.setUpper("37.5");
            setting.setLower("35");
            setting.setTemperatureFreq("120");
            this.save(setting);
            log.info("创建 体温 配置记录 imei: {}" ,id);
        }
        return setting;
    }

}
